import 'result_analyzed.dart';

extension Result on ResponseAnalyzed {

  bool get dataIsMap => data is Map;
  bool get dataIsList => data is List;
  bool get dataIsString => data is String;

  bool get dataIsEmpty {
    if (data == null) return true;
    if (data is Map) return (data as Map).isEmpty;
    if (data is List) return (data as List).isEmpty;
    if (data is String) return (data as String).isEmpty;
    return false;
  }

  bool get isNullOrEmpty {
    if (data == null) return true;
    if (data is String) return (data as String).isEmpty;
    if (data is List) return (data as List).isEmpty;
    if (data is Map) return (data as Map).isEmpty;
    return false;
  }

  bool get dataIsNotNullOrNotEmpty {
    if (data == null) return true;
    if (data is Map) return (data as Map).isNotEmpty;
    if (data is List) return (data as List).isNotEmpty;
    if (data is String) return (data as String).isNotEmpty;
    return false;
  }

  bool dataContainsKey(String key) {
    if (data is Map) return (data as Map).containsKey(key);
    return false;
  }
}

extension DynamicExtention on dynamic {

  bool get isNull             => this == null;
  bool get isNotNull          => this != null;

  bool get isEmpty            => this.isEmpty;
  bool get isNotEmpty         => this.isNotEmpty;

  bool get isInt              => this is int;
  bool get isBool             => this is bool;
  bool get isDouble           => this is double;


  bool get isMap              => this is Map;
  bool get isList             => this is List;
  bool get isString           => this is String;


  bool get isNullOrEmpty {
    if (this == null) return true;
    if (this is String) return (this as String).isEmpty;
    if (this is List) return (this as List).isEmpty;
    if (this is Map) return (this as Map).isEmpty;
    return false;
  }

  bool get isNotNullOrNotEmpty {
    if (this == null) return false;
    if (this is String) return (this as String).isNotEmpty;
    if (this is List) return (this as List).isNotEmpty;
    if (this is Map) return (this as Map).isNotEmpty;
    return true;
  }

  bool containsKey(String key) {
    if (this is Map) return (this as Map).containsKey(key);
    return false;
  }
}
